//
//  ForgetPassWordViewController.m
//  WHB_driver
//
//  Created by 徐国庆 on 15/12/28.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "ForgetPassWordViewController.h"
#import "ForgetPassWordCell.h"

@interface ForgetPassWordViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSArray     *imagesNameArray;
@property(nonatomic, strong) NSArray     *labelContentArray;

@end

@implementation ForgetPassWordViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.imagesNameArray = [NSArray arrayWithObjects:@"mi-1", @"mi-1", @"mi-1", nil];
        self.labelContentArray = [NSArray arrayWithObjects:@"请输入手机号", @"请输入验证码", @"密码", nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"忘记密码";
    [self initWithView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentifer = @"forgetPassWordCell";
    ForgetPassWordCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[ForgetPassWordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
    }
//    cell.textLabel.text = @"fasdf";
    cell.textImageView.image = [UIImage imageNamed:[self.imagesNameArray objectAtIndex:indexPath.row]];
    cell.contentTextField.placeholder = [self.labelContentArray objectAtIndex:indexPath.row];
    cell.lineLabel.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    cell.QrCodeButton.layer.masksToBounds = YES;
    cell.QrCodeButton.layer.cornerRadius = (cell.frame.size.height - 20) / 2;
    cell.QrCodeButton.layer.borderColor = [UIColor HexStrWithColor:@"f8cc00"].CGColor;
    cell.QrCodeButton.layer.borderWidth = 1.5;
    if (indexPath.row == 1) {
        [cell.QrCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [cell.QrCodeButton setTitleColor:[UIColor HexStrWithColor:@"333333"] forState:UIControlStateNormal];
        cell.QrCodeButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [cell.QrCodeButton addTarget:self action:@selector(qrCodeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    } else if (indexPath.row == 2){
        [cell.QrCodeButton setImage:[UIImage imageNamed:@"button_Password_eye_grey_open"] forState:UIControlStateNormal];
        cell.QrCodeButton.layer.borderColor = [UIColor whiteColor].CGColor;
        
    } else if (indexPath.row == 0){
        cell.QrCodeButton.hidden = YES;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

#pragma mark 头
- (UIView *)headerView{
    
    UIView *bottom = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    bottom.backgroundColor = [UIColor whiteColor];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((kUIScreenWidth - 100) / 2, (bottom.frame.size.height - 100) / 2, 100, 100)];
    imageView.image = [UIImage imageNamed:@"logo"];
    [bottom addSubview:imageView];
    return bottom;
}

#pragma mark 获取验证码点击事件
- (void)qrCodeButtonAction:(UIButton *)button{
    NSLog(@"获取验证码");
    [button setTitle:@"59秒" forState:UIControlStateNormal];
}

#pragma mark 返回按钮点击事件
- (void)returnButtonAction:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 *  初始化视图
 */
- (void)initWithView{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 导航栏
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kStateHeight + kNavHeight)];
    topView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:topView];
    
    // 导航栏标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, kUIScreenWidth, 40)];
    titleLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    titleLabel.text = @"忘记密码";
    titleLabel.textAlignment = 1;
    titleLabel.font = [UIFont systemFontOfSize:15 weight:2];
    [topView addSubview:titleLabel];
    
    // 导航栏左侧返回按钮
    UIButton *returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
    returnButton.frame = CGRectMake(0, 25, 30, 30);
    [returnButton setImage:[UIImage imageNamed:@"zuo"] forState:UIControlStateNormal];
    [returnButton addTarget:self action:@selector(returnButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:returnButton];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kStateHeight + kNavHeight + 5, kUIScreenWidth, kUIScreenHeight - kNavHeight - 90 - kStateHeight + 40) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.tableView];
    self.tableView.tableFooterView = [self footerView];
    self.tableView.tableHeaderView = [self headerView];
    //    self.tableView.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    self.tableView.backgroundColor = [UIColor whiteColor];
}


// 脚视图
- (UIView *)footerView{
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, kUIScreenWidth, 100)];
    
    UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    footerButton.frame = CGRectMake(50, 40, kUIScreenWidth - 100, 45);
    footerButton.layer.masksToBounds = YES;
    footerButton.layer.cornerRadius = 22.5;
    [footerButton setTitleColor:[UIColor HexStrWithColor:@"1b1b1b"] forState:UIControlStateNormal];
    [footerButton setTitle:@"重置密码" forState:UIControlStateNormal];
    footerButton.backgroundColor = [UIColor HexStrWithColor:@"f8cc00"];
    [footerButton addTarget:self action:@selector(footerButtonAction:) forControlEvents:UIControlEventTouchDown];
    [bottomView addSubview:footerButton];
    return bottomView;
}

#pragma mark 重置密码按钮点击事件
- (void)footerButtonAction:(UIButton *)button{
    
    
    NSString *tempStr = [UtilsHelper MD5:@"123456"];
    [DataController resetPassword:@""
                           telNum:@"13704808888"
                 verificationCode:@"123456"
                      newPassword:tempStr
                         userType:@"2"
                        withBlock:^(NSDictionary *result) {
                            NSLog(@"result == %@", result);
                            if ([[result objectForKey:@"resCode"] isEqualToString:@"0"]) {
                                NSLog(@"操作成功");
                            } else if ([[result objectForKey:@"resCode"] isEqualToString:@"2"]){
                                NSLog(@"踢掉前一个用户");
                            }
                        }];
     
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
